package com.imooc.distributedemo.resume.thread;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;

public class MyThreadClient {

    public static void main(String[] args) {
        // java线程池顺序执行任务
        MyThread task1 = new MyThread("task1");
        MyThread task2 = new MyThread("task2");
        MyThread task3 = new MyThread("task3");
        ExecutorService executor = Executors.newSingleThreadExecutor();
        try {
            executor.submit(task1);
            executor.submit(task2);
            executor.submit(task3);
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            executor.shutdown();
        }
        // 有依赖关系的任务调度
        /*ScheduledExecutorService executor1 = Executors.newScheduledThreadPool(1);
        try {
            ScheduledFuture<?> future1 = executor1.schedule(task1, 0, TimeUnit.SECONDS);
            ScheduledFuture<?> future2 = executor1.schedule(task2, future1.get(), TimeUnit.SECONDS);
            ScheduledFuture<?> future3 = executor1.schedule(task3, future2.get(), TimeUnit.SECONDS);
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            executor1.shutdown();
        }*/

        ThreadLocal<String> threadLocalData = new ThreadLocal<>();
        threadLocalData.set("123");
    }
}
